// <copyright file="EasyWebApp.cs" company="<Customer Name>">This is a "work-for-hire". or Copyright (C) 2010 MicroCODE Incorporated Troy, MI</copyright><author><Class Author's Name></author>

/*
 *      Title:    <Class Description>
 *      Module:   ClassTemplate (<Namespace>:ClassTemplate.cs)
 *      Project:  <Project Name>
 *      Customer: <Customer Name>
 *      Facility: MicroCODE Incorporated
 *      Date:     <Class Creation Date>
 *      Author:   <Class Author's Name>
 * 
 * 
 * 
 *  
 *      MODIFICATIONS:
 *      --------------
 *
 *  Date:         By-Group:   Rev:     Description:
 *
 *  DD-Mmm-YYYY   XYZ-GROUP  {0001}    Describe reason for creating or modifying class... 
 * 
 * 
 * 
 */
using System;
using System.Data;
using System.Reflection;
using Org.EasyWeb.Provider;
using Org.EasyWeb.Sys;

namespace Org.EasyWeb.Data
{
    public class BaseDataSet : DataSet, IDbDataSet
    {
        // Fields
        private Assembly fClassAssembly;
        private IDbConnection fConnection;
        private string fConnectionStr;
        private Attribute fCustomAttribute;

        // Methods
        public BaseDataSet()
        {
            // To be changed to "EasyWeb"
            base.DataSetName = "Toolkit";
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (disposing)
            {
                IDisposable fConnection = this.fConnection;
                if (fConnection != null)
                {
                    fConnection.Dispose();
                }
                else
                {
                    fConnection = null;
                }
                this.fCustomAttribute = null;
            }
        }

        protected virtual void Populate(BaseDataSet dataSet)
        {
            this.ConnectionStr = dataSet.ConnectionStr;
            this.ClassAssembly = dataSet.ClassAssembly;
        }

        // Properties
        public Assembly ClassAssembly
        {
            get
            {
                return this.fClassAssembly;
            }
            set
            {
                this.fClassAssembly = value;
            }
        }

        public string ConnectionStr
        {
            get
            {
                return this.fConnectionStr;
            }
            set
            {
                this.fConnectionStr = value;
                this.DbConnection.ConnectionString = value;
            }
        }

        public DataSetAttribute CustomAttribute
        {
            get
            {
                if (this.fCustomAttribute == null)
                {
                    this.fCustomAttribute = Attribute.GetCustomAttribute(base.GetType(), typeof(DataSetAttribute));
                }
                return (DataSetAttribute)this.fCustomAttribute;
            }
        }

        public IDbConnection DbConnection
        {
            get
            {
                if (this.fConnection == null)
                {
                    this.fConnection = GlobalProvider.Connection;
                }
                return this.fConnection;
            }
        }
    }
}
